package com.david.flowable.controller;

import com.david.flowable.service.FlowInstanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.david.common.utils.ResultUtils.success;

@RestController
@RequestMapping("/flowable/instance")
@Slf4j
public class FlowInstanceController {

    @Autowired
    private FlowInstanceService flowInstanceService;
    
    /**
    * @Description: 启动流程实例
    * @Param: [flowId, variables]
    * @return: org.springframework.http.ResponseEntity<java.lang.Object>
    * @Author: david
    * @Date: 2024/8/13
    */
    @PostMapping("/start/{flowId}")
    public ResponseEntity<Object> start(@PathVariable String flowId, @RequestBody Map<String, Object> variables){
        log.info("启动流程{},参数{}",flowId,variables);
        String instanceId = flowInstanceService.startFlowInstanceById(flowId, variables);
//        log.info("结束流程");
        return success(true,instanceId);
    }

    /**
    * @Description: 获取流程发起的表单信息
    * @Param: [procInsId]
    * @return: org.springframework.http.ResponseEntity<java.lang.Object>
    * @Author: david
    * @Date: 2024/8/13
    */
    @GetMapping("/get/{procInsId}")
    public ResponseEntity<Object> getStartForm(@PathVariable String procInsId){
        log.info("获取流程实例发起表单{}",procInsId);
        return success(true,flowInstanceService.getStartForm(procInsId));
    }
}
